import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:im_app/im/page/bloc/CollectListCubit.dart';
import 'package:im_app/im/page/sub/ImCollectListPage.dart';
import 'package:im_app/im/page/sub/ImSettingPage.dart';
import 'package:im_app/im/page/view/ListSeparator.dart';
import 'package:im_app/im/page/view/MovableView.dart';
import 'package:im_app/im/page/view/component/UserIconView.dart';
import 'package:im_app/im/util/ImConstant.dart';
import '../pojo/ImPojo.dart';
import 'bloc/SessionCubit.dart';

class MePage extends StatelessWidget {

  final ImUser loginUser;

  const MePage({ required this.loginUser, super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // appBar: _buildAppBar(),
        backgroundColor: ImConstant.IM_MAIN_BACKGROUND_COLOR,
        body: SafeArea(
          child: MovableView(
            headMoveMaxHeight: 100,
            trailMoveMaxHeight: 100,
            backgroundColor: ImConstant.IM_MAIN_BACKGROUND_COLOR,
            widgetBuilder: (context) =>
                Column(
                  children: [
                    _buildHeadItem(context),
                    const SizedBox(height: 10,),
                    Material(
                      color: ImConstant.IM_RESERVE_BACKGROUND_COLOR,
                      child: ListTile(
                        leading: const Icon(Icons.house_siding),
                        title: const Text('收藏'),
                        trailing: const Icon(Icons.chevron_right),
                        onTap: () {
                          Navigator.of(context).push(MaterialPageRoute(builder: (context) {
                            return BlocProvider(create: (context)=>CollectListCubit(), child: const ImCollectListPage(),);
                          }, settings: const RouteSettings(name: '/CollectListPage')));
                        },
                      ),
                    ),
                    ListSeparator(indent: 0, endIndent: 0,),
                    Material(
                      color: ImConstant.IM_RESERVE_BACKGROUND_COLOR,
                      child: ListTile(
                        leading: const Icon(Icons.settings),
                        title: const Text('设置'),
                        trailing: const Icon(Icons.chevron_right),
                        onTap: (){
                          Navigator.of(context).push(MaterialPageRoute(builder: (context) {
                            return const ImSettingPage();
                          }));
                        },
                      ),
                    ),
                  ],
                ),
          ),
        ));
  }

  Widget _buildHeadItem(BuildContext context) {
    var sessionCubit = context.watch<SessionCubit>();
    return Container(
        padding: const EdgeInsets.only(left: 10, right: 10, bottom: 20),
        color: ImConstant.IM_RESERVE_BACKGROUND_COLOR,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.end,
          children: [
            UserIconView(user: loginUser, iconSize: ImConstant.IM_USER_ICON_SIZE + 10,),

            Expanded(
              child: Padding(
                  padding: const EdgeInsets.only(left: 10),
                  child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Padding(
                          padding: const EdgeInsets.only(bottom: 10),
                          child: Text(sessionCubit.state.user.userName ?? ''),
                        ),
                        Text('')
                      ])),
            ),
            const Icon(
              Icons.qr_code,
              size: 18,
            ),
            const Padding(
              padding: EdgeInsets.only(right: 10),
              child: Icon(
                Icons.arrow_right,
                size: 18,
              ),
            )
          ],
        ));
  }
}
